package com.ruoyi.ok.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ok.domain.TbOk;
import com.ruoyi.ok.service.ITbOkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 点赞Controller
 * 
 * @author 劳雅玲
 * @date 2024-05-04
 */
@RestController
@RequestMapping("/ok/ok")
public class TbOkController extends BaseController
{
    @Autowired
    private ITbOkService tbOkService;

    /**
     * 查询点赞列表
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbOk tbOk)
    {
        startPage();
        List<TbOk> list = tbOkService.selectTbOkList(tbOk);
        return getDataTable(list);
    }

    /**
     * 导出点赞列表
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:export')")
    @Log(title = "点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOk tbOk)
    {
        List<TbOk> list = tbOkService.selectTbOkList(tbOk);
        ExcelUtil<TbOk> util = new ExcelUtil<TbOk>(TbOk.class);
        util.exportExcel(response, list, "点赞数据");
    }

    /**
     * 获取点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbOkService.selectTbOkById(id));
    }

    /**
     * 新增点赞
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:add')")
    @Log(title = "点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOk tbOk)
    {
        return toAjax(tbOkService.insertTbOk(tbOk));
    }

    /**
     * 点赞/取消点赞
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:cancel')")
    @Log(title = "点赞", businessType = BusinessType.INSERT)
    @DeleteMapping("/cancel")
    public AjaxResult cancel(@RequestBody TbOk tbOk)
    {
        tbOk.setUserId(getUserId());
        return toAjax(tbOkService.cancel(tbOk));
    }

    /**
     * 修改点赞
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:edit')")
    @Log(title = "点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOk tbOk)
    {
        return toAjax(tbOkService.updateTbOk(tbOk));
    }

    /**
     * 删除点赞
     */
    @PreAuthorize("@ss.hasPermi('ok:ok:remove')")
    @Log(title = "点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbOkService.deleteTbOkByIds(ids));
    }
}
